package com.game.model.equip;

import com.game.config.Numerical;
import com.game.model.BaseProperty;
import com.game.model.SpecialProperty;
import com.game.model.goods.Goods;
import com.game.model.api.GoodsType;
import com.game.model.api.Quality;
import com.game.model.role.Role;

import java.io.Serializable;

//装备
public abstract class Equip extends Goods implements Serializable {
    private int level;//装备等级
    private BaseProperty baseProperty;//基本属性
    private SpecialProperty specialProperty;//特殊属性

    public Equip() {
    }

    public Equip(int id, GoodsType type, String name, Quality quality, int useLevel, String description, int level, BaseProperty baseProperty, SpecialProperty specialProperty) {
        super(id, type, name, quality, useLevel, description);
        this.level = level;
        this.specialProperty = specialProperty;
        this.baseProperty = baseProperty;
    }


    //将装备穿附给角色
    public Role equipRole(Role role) {
        //计算强化后的装备
        long hp = baseProperty.getHP();
        long mp = baseProperty.getMp();
        long atk = baseProperty.getATK();
        long def = baseProperty.getDEF();
        int hit = specialProperty.getHIT();
        int cri = specialProperty.getCRI();
        int avo = specialProperty.getAVO();
        int chr = specialProperty.getCHR();
        //新角色属性=装备属性+原来角色属性
        hp = Numerical.calculateEquipBase(level, hp) + role.getBaseProperty().getHP();
        mp = Numerical.calculateEquipBase(level, mp) + role.getBaseProperty().getMp();
        atk = Numerical.calculateEquipBase(level, atk) + role.getBaseProperty().getATK();
        def = Numerical.calculateEquipBase(level, def) + role.getBaseProperty().getDEF();
        hit = Numerical.calculateEquipSpecial(level, hit) + role.getSpecialProperty().getHIT();
        cri = Numerical.calculateEquipSpecial(level, cri) + role.getSpecialProperty().getCRI();
        avo = Numerical.calculateEquipSpecial(level, avo) + role.getSpecialProperty().getAVO();
        chr = Numerical.calculateEquipSpecial(level,chr) +role.getSpecialProperty().getCHR();
        //附加到角色
        role.setBaseProperty(new BaseProperty(hp, mp, atk, def));
        role.setSpecialProperty(new SpecialProperty(hit, cri, avo,chr));
        return role;
    }

    @Override
    public String toString() {
        return "Equip{" +
                "id=" + super.getId() +
                ", level=" + level +
                ", baseProperty=" + baseProperty +
                ", specialProperty=" + specialProperty +
                '}';
    }


    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public BaseProperty getBaseProperty() {
        return baseProperty;
    }

    public void setBaseProperty(BaseProperty baseProperty) {
        this.baseProperty = baseProperty;
    }

    public SpecialProperty getSpecialProperty() {
        return specialProperty;
    }

    public void setSpecialProperty(SpecialProperty specialProperty) {
        this.specialProperty = specialProperty;
    }

}
